#include <stdio.h>
#include <stdlib.h>
typedef struct BstNode
{
    struct BstNode *left;
    struct BstNode *right;
    int value;
}BN;
BN* insert(BN *root, int val);
void pre_order(BN *root);
void in_order(BN *root);
void post_order(BN *root);

int main()
{
    BN * root = NULL;
    root = insert(root,10);
    root = insert(root,5);
    root = insert(root,15);
    root = insert(root,2);
    root = insert(root,16);
    root = insert(root,15);
    root = insert(root,13);
    pre_order(root);
    printf("\n");
    in_order(root);
    printf("\n");
    post_order(root);
    printf("\n");
    return 0;
}
BN* insert(BN *root, int val)
{
    if(root == NULL)
    {
        BN *newnode = malloc(sizeof(BN));
        root = newnode;
        newnode->left = NULL;
        newnode->right = NULL;
        newnode->value = val;
        return root;
    }
    //大于根的值
    if(root->value < val)
    {
        root->right = insert(root->right, val);
    }
    else{
        root->left = insert(root->left, val);
    }
    return root;
}
//先序遍历
void pre_order(BN *root)
{
    if(root==NULL)
        return;
    printf("%d  ", root->value);
    pre_order(root->left);
    pre_order(root->right);
}
void in_order(BN *root)
{
    if(root==NULL)
        return;
    in_order(root->left);
    printf("%d  ", root->value);
    in_order(root->right);
}
void post_order(BN *root)
{
    if(root==NULL)
        return;
    post_order(root->left);
    post_order(root->right);
    printf("%d  ", root->value);
}